<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <link rel="StyleSheet" type="text/css" href="/tpa/admin.css" />
      <script type="text/javascript" src="/lib/js/jquery.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.ui.js"></script>
      <script type="text/javascript" src="/lib/js/meccano.js"></script>
      <script type="text/javascript">
         $(document).ready(function(){
            $('#fieldset_langs').sortable({'items':'>div','handle':'.moveable','revert':true,'update':function(e, ui){
                  var pos_string = 'ajaxmode=1';
                  $('#fieldset_langs input[name=id]').each(function(){
                     pos_string += '&position[]='+$(this).attr('value');
                  });
                  $.ajax({
                     url: '/admin/langs.html',
                     data: pos_string,
                     dataType: 'json',
                     type: 'POST',
                     error: function(){
                        $('#fieldset_langs').sortable('cancel');
                     },
                     success: function(data){
                        if(!data.success)
                           $('#fieldset_langs').sortable('cancel');
                     }
                  });
            }});
            $('#fieldset_langs form').bind('change', function(){
               $('a.i_ok, a.i_exclamation', this).removeClass('i_ok').addClass('i_save');
            });
         });
         function saveLanguage(id)
         {
            $('#lang_area_'+id+' a.i_save').removeClass('i_save').addClass('i_loading');
            $.ajax({
               url: '/admin/langs.html',
               data: $('#lang_area_'+id).serialize() +'&ajaxmode=1',
               dataType: 'json',
               type: 'POST',
               error: function()
               {
                  $('#lang_area_'+id+' a.i_loading').removeClass('i_loading').addClass('i_exclamation');
               },
               success: function(data) {
                  if(data.success)
                  {
                     $('#lang_area_'+id+' a.i_loading').removeClass('i_loading').addClass('i_ok');
                     if(data.active)
                        $('#lang_area_'+id).parent().removeClass('inactive');
                     else
                        $('#lang_area_'+id).parent().addClass('inactive');
                  } else
                  {
                     $('#lang_area_'+id+' a.i_loading').removeClass('i_loading').addClass('i_exclamation');
                  }
               }
            });
         }
      </script>
   </head>
   <body>

      <div align="center" style="padding-top:40px;" id="fieldset_langs">
         {%foreach from=$data item='l'%}
         <div style="width: 700px;" class="fieldset{%if $l.active neq 1%} inactive{%/if%}">
            <form id="lang_area_{%$l.id%}">
               <input type="hidden" value="{%$l.id%}" name="id" />
               <table border="0" cellpadding="3" cellspacing="0">
                  <tr>
                     <td><label for="alias_{%$l.id%}">{%$TR->meccano->alias%}:</label></td>
                     <td><input type="text" name="alias" id="alias_{%$l.id%}" value="{%$l.alias%}" /></td>
                  </tr>
                  <tr>
                     <td><label for="iso_{%$l.id%}">ISO:</label></td>
                     <td><input type="text" name="iso" id="iso_{%$l.id%}" value="{%$l.iso%}" /></td>
                  </tr>
                  <tr>
                     <td><label for="title_{%$l.id%}">{%$TR->meccano->title%}:</label></td>
                     <td><input type="text" name="title" id="title_{%$l.id%}" value="{%$l.title%}" /></td>
                  </tr>
                  {%if $CONFIG->langs_domain%}
                  <tr>
                     <td><label for="domain_{%$l.id%}">{%$TR->meccano->domain%}:</label></td>
                     <td><input type="text" name="domain" id="domain_{%$l.id%}" value="{%$l.domain%}" /></td>
                  </tr>
                  {%/if%}
                  <tr>
                     <td><label for="charset_{%$l.id%}">{%$TR->meccano->charset%}:</label></td>
                     <td><input type="text" name="charset" id="charset_{%$l.id%}" value="{%$l.charset%}" /></td>
                  </tr>
                  <tr>
                     <td><label for="datef_{%$l.id%}">{%$TR->meccano->dateformat%}:</label></td>
                     <td><input type="text" name="datef" id="datef_{%$l.id%}" value="{%$l.dateformat%}" /></td>
                  </tr>
                  <tr>
                     <td><label for="active_{%$l.id%}">{%$TR->meccano->active%}</label></td>
                     <td><input type="checkbox" name="active" value="1"{%if $l.active eq 1%} checked{%/if%} /></td>
                  </tr>
               </table>
               <div class="manage">
                  <a class="moveable">{%$TR->meccano->move%}</a>
                  <a href="javascript:void(0)" onclick="saveLanguage({%$l.id%});" class="a_icon i_save">{%$TR->meccano->save%}</a><br />
               </div>
            </form>
         </div>
         {%/foreach%}
      </div>
   </body>
</html>